# 新闻模块
import random
import re
from flask import request, make_response, current_app, jsonify
from flask import session,render_template

from info import redis_store, constants, db
from info.libs.yuntongxun.sms import CCP
from info.models import User, News
from info.utils.response_code import RET
from . import news_blue
from info.utils.captcha.captcha import captcha


@news_blue.route('/<int:new_id>')
def get_news(new_id):
    new_list = []
    try:
        new_list = News.query.order_by(News.clicks.desc()).limit(constants.CLICK_RANK_MAX_NEWS)
    except Exception as e:
        current_app.logger.error(e)

    news_dict_li = []
    for news in new_list:
        # print(news)
        news_dict_li.append(news.to_basic_dict())
    data={
        'news_dict_li': news_dict_li
    }

    return render_template('news/detail.html', data=data)